package cn.lbf.stuniversity.equipment.controller;


import cn.lbf.stuniversity.equipment.entity.Equipment;
import cn.lbf.stuniversity.equipment.form.*;
import cn.lbf.stuniversity.equipment.service.EquipmentService;
import cn.lbf.stuniversity.vo.Result;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/equip")
@CrossOrigin
public class EquipmentController {
    @Autowired
    private EquipmentService equipmentService;
    @PostMapping("/addNew")
    public Result<Map<String,Object>> addNew(@Valid @RequestBody EquipmentAddForm form){
        return equipmentService.addNew(form);
    }

    @GetMapping("/queryList")
    public Result<Page<Equipment>> queryList(@Valid EquipmentForm form){
        System.out.println(form);
        return equipmentService.queryList(form);
    }

    @GetMapping("/del")
    public Result<String> del(String equipmentId){
        return equipmentService.del(equipmentId);
    }

    @PostMapping("/edit")
    public Result<String> edit(@Valid @RequestBody EquipmentDetailForm form){
        return equipmentService.updateById(form);
    }

}
